import { Client, version } from "./src/mod.ts";
import type { ClientOptions, ResponseType } from "./src/mod.ts";
import { UserAPI } from "./src/user.ts";
import type { User, AccessToken, Email, PublicKey, CreateKeyOption, CreateAccessTokenOption } from "./src/user.ts";
import { RepositoryAPI } from "./src/repo.ts";
import type { Repository, Permission, ForkRepoOption, CreateRepoOption, MigrateRepoOption, EditIssueTrackerOption, EditWikiOption } from "./src/repo.ts";
import { IssueAPI } from "./src/issue.ts";
import type { 
  Issue, 
  Label, 
  Milestone, 
  StateType, 
  ListIssueOption,
  CreateIssueOption,
  EditIssueOption,
  CreateLabelOption,
  EditLabelOption,
  IssueLabelsOption,
  CreateMilestoneOption,
  EditMilestoneOption,
  PullRequestMeta,
  Comment
} from "./src/issue.ts";
import { OrganizationAPI } from "./src/org.ts";
import type {
  Organization,
  Team,
  CreateOrgOption,
  EditOrgOption,
  AddOrgMembershipOption,
  CreateTeamOption
} from "./src/org.ts";
import { PullRequestAPI } from "./src/pull.ts";
import type { PullRequest } from "./src/pull.ts";
import { ReleaseAPI } from "./src/release.ts";
import type { Release, CreateReleaseOption, EditReleaseOption } from "./src/release.ts";
import { Branch, PayloadCommit } from "./src/repo_branch.ts";
import { DeployKey } from "./src/repo_key.ts";
import { Hook, CreateHookOption, EditHookOption, HookAPI, 
  CreatePayload, DeletePayload, ForkPayload, PushPayload, 
  IssuesPayload, HookIssueAction, ChangesFromPayload, ChangesPayload,
  IssueCommentPayload, HookIssueCommentAction, PullRequestPayload,
  ReleasePayload, HookReleaseAction, PusherType, Payloader
} from "./src/repo_hook.ts";
import { Collaborator, AddCollaboratorOption } from "./src/repo_collaborator.ts";
import { Commit, CommitMeta, CommitUser, RepoCommit } from "./src/repo_commit.ts";
import { AdminAPI } from "./src/admin.ts";
import type { CreateUserOption, EditUserOption, AdminForkRepoOption } from "./src/admin.ts";
import { MiscellaneousAPI, MediaTypes } from "./src/utils.ts";
import type { MarkdownOption } from "./src/utils.ts";

/**
 * Main class to access Gogs API
 */
export class GogsClient {
  private client: Client;
  
  // API endpoints
  public users: UserAPI;
  public repos: RepositoryAPI;
  public issues: IssueAPI;
  public orgs: OrganizationAPI;
  public pulls: PullRequestAPI;
  public releases: ReleaseAPI;
  public admin: AdminAPI;
  public misc: MiscellaneousAPI;
  public hooks: HookAPI;

  /**
   * Creates a new Gogs API client
   */
  constructor(options: ClientOptions) {
    this.client = new Client(options);
    
    // Initialize API endpoints
    this.users = new UserAPI(this.client);
    this.repos = new RepositoryAPI(this.client);
    this.issues = new IssueAPI(this.client);
    this.orgs = new OrganizationAPI(this.client);
    this.pulls = new PullRequestAPI(this.client);
    this.releases = new ReleaseAPI(this.client);
    this.admin = new AdminAPI(this.client);
    this.misc = new MiscellaneousAPI(this.client);
    this.hooks = new HookAPI(this.client);
  }

  /**
   * Get current client version
   */
  getVersion(): string {
    return version();
  }
}

// Export values
export { Client, version, MediaTypes };

// Export types
export type {
  ClientOptions,
  ResponseType,
  User,
  Repository,
  Permission,
  CreateRepoOption,
  MigrateRepoOption,
  EditIssueTrackerOption,
  EditWikiOption,
  ForkRepoOption,
  Issue,
  Label,
  Milestone, 
  StateType,
  PullRequestMeta,
  ListIssueOption,
  CreateIssueOption,
  EditIssueOption,
  CreateLabelOption,
  EditLabelOption,
  IssueLabelsOption,
  CreateMilestoneOption,
  EditMilestoneOption,
  Organization,
  Team,
  PullRequest,
  Release,
  Branch,
  PayloadCommit,
  DeployKey,
  Hook,
  CreateHookOption,
  EditHookOption,
  AccessToken,
  Email,
  PublicKey,
  CreateKeyOption,
  CreateAccessTokenOption,
  Comment,
  CreateOrgOption,
  EditOrgOption,
  AddOrgMembershipOption,
  CreateTeamOption,
  CreateReleaseOption,
  EditReleaseOption,
  CreateUserOption,
  EditUserOption,
  MarkdownOption,
  Collaborator,
  AddCollaboratorOption,
  Commit,
  CommitMeta,
  CommitUser,
  RepoCommit,
  // Webhook payload types
  Payloader,
  CreatePayload,
  DeletePayload,
  ForkPayload,
  PushPayload,
  IssuesPayload,
  HookIssueAction,
  ChangesFromPayload,
  ChangesPayload,
  IssueCommentPayload,
  HookIssueCommentAction,
  PullRequestPayload,
  ReleasePayload,
  HookReleaseAction,
  PusherType,
  AdminForkRepoOption
}; 